#pragma once
#include "HashTable.hpp"

namespace yiwei
{
	template<class K>
	struct SetKeyOfT
	{
		const K& operator()(const K& key)
		{
			return key;
		}
	};
	template<class K,class Hash = _Hash<K>>
	class unordered_set
	{
	public:
		typedef typename HashTable<K, K, SetKeyOfT<K>, Hash>::iterator iterator;
		typedef typename HashTable<K, K, SetKeyOfT<K>, Hash>::const_iterator const_iterator;

		unordered_set() {}

		unordered_set(const unordered_set& us)
			:_ht(us._ht)
		{}

		unordered_set& operator=(const unordered_set& us)
		{
			_ht = us._ht;
			return *this;
		}

		std::pair<iterator, bool> insert(const K& key)
		{
			return _ht.Insert(key);
		}

		iterator begin()
		{
			return _ht.begin();
		}

		const_iterator begin() const
		{
			return _ht.begin();
		}

		iterator end()
		{
			return _ht.end();
		}

		const_iterator end() const
		{
			return _ht.end();
		}

		iterator find(const K& key)
		{
			return _ht.Find(key);
		}

		const_iterator find(const K& key) const
		{
			return _ht.Find(key);
		}

		bool erase(const K& key)
		{
			return _ht.Erase(key);
		}

		bool erase(const iterator& it)
		{
			SetKeyOfT<K> koft;
			return _ht.Erase(koft(*it));
		}
	private:
		HashTable<K, K, SetKeyOfT<K>, Hash> _ht;
	};
}